package com.ruoyi.merchant.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.merchant.domain.CfMerchant;
import com.ruoyi.merchant.service.ICfMerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.merchant.domain.CfMerchantVerification;
import com.ruoyi.merchant.service.ICfMerchantVerificationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商户认证Controller
 * 
 * @author ruoyi
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/merchantVerification")
public class CfMerchantVerificationController extends BaseController
{
    @Autowired
    private ICfMerchantVerificationService cfMerchantVerificationService;
    @Autowired
    private ICfMerchantService cfMerchantService;
    /**
     * 查询商户认证列表
     */
    @RequiresPermissions("merchant:merchantVerification:list")
    @GetMapping("/list")
    public TableDataInfo list()
    {
        startPage();
        List<CfMerchantVerification> list = cfMerchantVerificationService.getMerchantByMerchantId();
        return getDataTable(list);
    }

    /**
     * 导出商户认证列表
     */
    @RequiresPermissions("merchant:merchantVerification:export")
    @Log(title = "商户认证", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CfMerchantVerification cfMerchantVerification)
    {
        List<CfMerchantVerification> list = cfMerchantVerificationService.selectCfMerchantVerificationList(cfMerchantVerification);
        ExcelUtil<CfMerchantVerification> util = new ExcelUtil<CfMerchantVerification>(CfMerchantVerification.class);
        util.exportExcel(response, list, "商户认证数据");
    }

    /**
     * 获取商户认证详细信息
     */
    @RequiresPermissions("merchant:merchantVerification:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cfMerchantVerificationService.selectCfMerchantVerificationById(id));
    }

    /**
     * 新增商户认证
     */
    @RequiresPermissions("merchant:merchantVerification:add")
    @Log(title = "商户认证", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CfMerchantVerification cfMerchantVerification)
    {
        //创建商户
        CfMerchant merchant = new CfMerchant();
        //设置未删除
        merchant.setDeleted("0");
        merchant.setIsRegister("0");
        //添加一个只有id的空商户
        long cfMerchantId = (long)cfMerchantService.insertCfMerchant(merchant) ;
        //注册表添加商户表的id
        cfMerchantVerification.setMid(merchant.getMerchantId());
        return toAjax(cfMerchantVerificationService.insertCfMerchantVerification(cfMerchantVerification));
    }

    /**
     * 修改商户认证
     */
    @RequiresPermissions("merchant:merchantVerification:edit")
    @Log(title = "商户认证", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CfMerchantVerification cfMerchantVerification)
    {
        return toAjax(cfMerchantVerificationService.updateCfMerchantVerification(cfMerchantVerification));
    }

    /**
     * 删除商户认证
     */
    @RequiresPermissions("merchant:merchantVerification:remove")
    @Log(title = "商户认证", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cfMerchantVerificationService.deleteCfMerchantVerificationByIds(ids));
    }
}
